
import unittest

from Schedule.TwoWeekServiceCycleEvaluator import TwoWeekServiceCycleEvaluator
from Schedule.Doctors import Doctors

class TwoWeekServiceCycleEvaluatorTestCases(unittest.TestCase):
        
    @staticmethod        
    def populateChromosome(chromosome, index, weekBoundary, rota):
        currentWeek = weekBoundary[0]
        weekNo = 0
        
        for x in index:
            if x > currentWeek and weekNo < 4:
                if weekNo < len(weekBoundary) - 1:
                    currentWeek = weekBoundary[weekNo + 1]
                weekNo += 1
            chromosome[x] = rota[weekNo]
        
    def setUp(self):
        
        self._initCount = dict()
        for i in range(0, len (Doctors().doctorNames)):
            self._initCount[i] = 0;
            
    def tearDown(self):
        pass

    def test_May1(self):
        nicuIndex = [2, 6, 10, 13, 16, 21, 25, 29, 32, 35, 40, 44, 48, 51, 54, 59, 63, 67, 70, 73, 79]
        stepDownIndex = [3, 7, 11, 14, 17, 22, 26, 30, 33, 36, 41, 45, 49, 52, 55, 60, 64, 68, 71, 74, 80]
        weekBoundary = [19, 38, 57, 76]

        rota = {
            'nicu': [Doctors().doctorIds['GUDAVALLI'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['GAD'], Doctors().doctorIds['GAD']], 
            'sd': [Doctors().doctorIds['SUK'], Doctors().doctorIds['RON'], Doctors().doctorIds['RON'], Doctors().doctorIds['SUK'], Doctors().doctorIds['SUK']]
        }

        chromosome = [0, 4, 1, 3, 5, 5, 2, 1, 4, 3, 0, 2, 0, 2, 1, 3, 1, 1, 5, 2, 3, 1, 4, 0, 0, 1, 4, 2, 4, 2, 4, 5, 2, 4, 0, 3, 3, 1, 4, 5, 3, 0, 1, 1, 1, 4, 2, 1, 3, 5, 5, 3, 3, 2, 1, 3, 4, 1, 3, 1, 0, 5, 5, 2, 0, 4, 0, 1, 3, 2, 0, 3, 1, 5, 4, 2, 2, 3, 0, 5, 2, 1]

        score = TwoWeekServiceCycleEvaluator(nicuIndex, stepDownIndex, weekBoundary, rota, self._initCount, 1).evaluate(chromosome)
                
        self.assertEquals(score, 12)        

    def test_MayMaximumScore(self):
        nicuIndex = [2, 6, 10, 13, 16, 21, 25, 29, 32, 35, 40, 44, 48, 51, 54, 59, 63, 67, 70, 73, 79]
        stepDownIndex = [3, 7, 11, 14, 17, 22, 26, 30, 33, 36, 41, 45, 49, 52, 55, 60, 64, 68, 71, 74, 80]
        weekBoundary = [19, 38, 57, 76]
        
        rota = {
            'nicu': [Doctors().doctorIds['GUDAVALLI'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['GAD'], Doctors().doctorIds['GAD']], 
            'sd': [Doctors().doctorIds['SUK'], Doctors().doctorIds['RON'], Doctors().doctorIds['RON'], Doctors().doctorIds['SUK'], Doctors().doctorIds['SUK']]
        }

        chromosome = [0, 5, 5, 5, 5, 5, 2, 1, 4, 3, 0, 2, 0, 2, 1, 3, 1, 1, 5, 2, 3, 1, 4, 0, 0, 1, 4, 2, 4, 2, 4, 5, 2, 4, 0, 3, 3, 1, 4, 5, 3, 0, 1, 1, 1, 4, 2, 1, 3, 5, 5, 3, 3, 2, 1, 3, 4, 1, 3, 1, 0, 5, 5, 2, 0, 4, 0, 1, 3, 2, 0, 3, 1, 5, 4, 2, 2, 3, 0, 5, 2, 5]
        
        TwoWeekServiceCycleEvaluatorTestCases.populateChromosome(chromosome, nicuIndex, weekBoundary, rota['nicu'])
        TwoWeekServiceCycleEvaluatorTestCases.populateChromosome(chromosome, stepDownIndex, weekBoundary, rota['sd'])
        
        score = TwoWeekServiceCycleEvaluator(nicuIndex, stepDownIndex, weekBoundary, rota, self._initCount, 1).evaluate(chromosome)
        
        self.assertEquals(score, 42)

    def test_JuneMaximumNicuScore(self):
        nicuIndex = [1, 4, 7, 12, 16, 20, 23, 26, 31, 35, 39, 42, 45, 50, 54, 58, 61, 64, 69, 73, 77, 80]
        stepDownIndex = [2, 5, 8, 13, 17, 21, 24, 27, 32, 36, 40, 43, 46, 51, 55, 59, 62, 65, 70, 74, 78, 81]
        weekBoundary = [10, 29, 48, 67]

        rota = {
            'nicu': [Doctors().doctorIds['GAD'], Doctors().doctorIds['RON'], Doctors().doctorIds['RON'], Doctors().doctorIds['SUK'], Doctors().doctorIds['SUK']], 
            'sd': [Doctors().doctorIds['SUK'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['GUDAVALLI'], Doctors().doctorIds['GUDAVALLI']]
        }

        chromosome = [0, 1, 5, 3, 5, 4, 2, 1, 1, 4, 0, 4, 3, 5, 2, 3, 2, 1, 0, 4, 0, 0, 5, 0, 4, 3, 0, 2, 2, 1, 0, 3, 1, 4, 5, 3, 2, 0, 5, 3, 1, 2, 3, 1, 1, 0, 4, 0, 5, 2, 0, 5, 3, 1, 4, 0, 5, 3, 0, 4, 0, 1, 5, 4, 1, 5, 1, 5, 3, 4, 5, 1, 2, 5, 5, 5, 4, 0, 5, 1, 2, 5]
        chromosome = [0, 4, 1, 3, 5, 5, 2, 1, 4, 3, 0, 2, 0, 2, 1, 3, 1, 1, 5, 2, 3, 1, 4, 0, 0, 1, 4, 2, 4, 2, 4, 5, 2, 4, 0, 3, 3, 1, 4, 5, 3, 0, 1, 1, 1, 4, 2, 1, 3, 5, 5, 3, 3, 2, 1, 3, 4, 1, 3, 1, 0, 5, 5, 2, 0, 4, 0, 1, 3, 2, 0, 3, 1, 5, 4, 2, 2, 3, 0, 5, 2, 1]

        TwoWeekServiceCycleEvaluatorTestCases.populateChromosome(chromosome, nicuIndex, weekBoundary, rota['nicu'])

        score = TwoWeekServiceCycleEvaluator(nicuIndex, stepDownIndex, weekBoundary, rota, self._initCount, 1).evaluate(chromosome, True)
                
        self.assertEquals(score, 27)        

    def test_JuneMaximumScore(self):
        nicuIndex = [1, 4, 7, 12, 16, 20, 23, 26, 31, 35, 39, 42, 45, 50, 54, 58, 61, 64, 69, 73, 77, 80]
        stepDownIndex = [2, 5, 8, 13, 17, 21, 24, 27, 32, 36, 40, 43, 46, 51, 55, 59, 62, 65, 70, 74, 78, 81]
        weekBoundary = [10, 29, 48, 67]

        rota = {
            'nicu': [Doctors().doctorIds['GAD'], Doctors().doctorIds['RON'], Doctors().doctorIds['RON'], Doctors().doctorIds['SUK'], Doctors().doctorIds['SUK']], 
            'sd': [Doctors().doctorIds['SUK'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['NADROO'], Doctors().doctorIds['GUDAVALLI'], Doctors().doctorIds['GUDAVALLI']]
        }

        chromosome = [0, 1, 5, 3, 5, 4, 2, 1, 1, 4, 0, 4, 3, 5, 2, 3, 2, 1, 0, 4, 0, 0, 5, 0, 4, 3, 0, 2, 2, 1, 0, 3, 1, 4, 5, 3, 2, 0, 5, 3, 1, 2, 3, 1, 1, 0, 4, 0, 5, 2, 0, 5, 3, 1, 4, 0, 5, 3, 0, 4, 0, 1, 5, 4, 1, 5, 1, 5, 3, 4, 5, 1, 2, 5, 5, 5, 4, 0, 5, 1, 2, 5]
        chromosome = [0, 4, 1, 3, 5, 5, 2, 1, 4, 3, 0, 2, 0, 2, 1, 3, 1, 1, 5, 2, 3, 1, 4, 0, 0, 1, 4, 2, 4, 2, 4, 5, 2, 4, 0, 3, 3, 1, 4, 5, 3, 0, 1, 1, 1, 4, 2, 1, 3, 5, 5, 3, 3, 2, 1, 3, 4, 1, 3, 1, 0, 5, 5, 2, 0, 4, 0, 1, 3, 2, 0, 3, 1, 5, 4, 2, 2, 3, 0, 5, 2, 1]

        TwoWeekServiceCycleEvaluatorTestCases.populateChromosome(chromosome, nicuIndex, weekBoundary, rota['nicu'])
        TwoWeekServiceCycleEvaluatorTestCases.populateChromosome(chromosome, stepDownIndex, weekBoundary, rota['sd'])

        score = TwoWeekServiceCycleEvaluator(nicuIndex, stepDownIndex, weekBoundary, rota, self._initCount, 1).evaluate(chromosome, True)
                
        self.assertEquals(score, 44)        

                
if __name__ == '__main__':
    unittest.main()
